找传奇、传世资源到传世资源站!
未分类 正文

c# mongodb实例源码(asp.net mvc实现)

  • 资源分类:未分类
  • 发 布 人:房东的猫
  • 文件大小:未知
  • 文件格式:.zip
  • 浏览次数:49
  • 下载次数: 3
  • 发布时间:9月4日

  • 标签: mongodbMVC
8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

实现了 对mongodb数据库的增删改 操作
c# mongodb实例源码(asp.net mvc实现) -第1张using System;using System.Collections.Generic;using System.Linq;using System.Web;using MongoDBMVC3.Models;using MongoDB;namespace MongoDBMVC3.Biz{ public class BizModel { public static Channel GetChannelbyID(Guid cid) { using (Mongo mg = new Mongo(DBcon._connectionString)) { mg.Connect(); var db = mg.GetDatabase(DBcon._channel); var list = db.GetCollection<Channel>(); var query = from c in list.Linq() select c; Channel channel = query.Where(c => c.ChannelId == cid).First(); return channel; } } public static List<Channel> GetChannel() { using (Mongo mg = new Mongo(DBcon._connectionString)) { mg.Connect(); var db = mg.GetDatabase(DBcon._channel); var list = db.GetCollection<Channel>(); var query = (from c in list.Linq() select c).ToList<Channel>(); return query; } } public static void AddChannel(Channel model) { using (Mongo mg = new Mongo(DBcon._connectionString)) { mg.Connect(); var db = mg.GetDatabase(DBcon._channel); var list = db.GetCollection<Channel>(); list.Insert(model); } } public static void UpdateChannel(Channel model) { using (Mongo mg = new Mongo(DBcon._connectionString)) { mg.Connect(); var db = mg.GetDatabase(DBcon._channel); var list = db.GetCollection<Channel>(); list.Update(model, c => c.ChannelId == model.ChannelId); } } public static void DeleteChannel(Guid cid) { using (Mongo mg = new Mongo(DBcon._connectionString)) { mg.Connect(); var db = mg.GetDatabase(DBcon._channel); var list = db.GetCollection<Channel>(); list.Remove(c => c.ChannelId == cid); } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复